home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTValOrderedVector<T> - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/tvordvec.h> RWTValOrderedVector<T> ordvec; PPPPlllleeeeaaaasssseeee NNNNooootttteeee!!!! IIIIffff yyyyoooouuuu ddddoooo nnnnooootttt hhhhaaaavvvveeee tttthhhheeee SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ddddeeeessssccccrrrriiiibbbbeeeedddd hhhheeeerrrreeee.... OOOOtttthhhheeeerrrrwwwwiiiisssseeee,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ttttoooo RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr described in the Class Reference. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr<<<<TTTT>>>> is an oooorrrrddddeeeerrrreeeedddd collection. That is, the items in the collection have a meaningful ordered relationship with respect to one another and can be accessed by an index number. The order is set by the order of insertion. Duplicates are allowed. The class is implemented as a vector, allowing efficient insertion and retrieval from the end of the collection, but somewhat slower from the beginning of the collection. The class TTTT must have: well-defined copy semantics (TTTT::::::::TTTT((((ccccoooonnnnsssstttt TTTT&&&&)))) or equivalent); well-defined assignment semantics (TTTT::::::::ooooppppeeeerrrraaaattttoooorrrr====((((ccccoooonnnnsssstttt TTTT&&&&)))) or equivalent); well-defined equality semantics (TTTT::::::::ooooppppeeeerrrraaaattttoooorrrr========((((ccccoooonnnnsssstttt TTTT&&&&))))); a default constructor. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee Note that an ordered vector has a lllleeeennnnggggtttthhhh (the number of items returned by lllleeeennnnggggtttthhhh(((()))) or eeeennnnttttrrrriiiieeeessss(((())))) and a ccccaaaappppaaaacccciiiittttyyyy. Necessarily, the capacity is always greater than or equal to the length. Although elements beyond the collection's length are not used, nevertheless, in a value-based collection, they are occupied. If each instance of class TTTT requires considerable resources, then you should ensure that the collection's capacity is not much greater than its length, otherwise unnecessary resources will be tied up. Isomorphic EEEExxxxaaaammmmpppplllleeee #include <rw/tvordvec.h> #include <rw/rstream.h> main() { RWTValOrderedVector<double> vec; vec.insert(22.0); vec.insert(5.3); vec.insert(-102.5); PPPPaaaaggggeeee 1111 RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) vec.insert(15.0); vec.insert(5.3); cout << vec.entries() << " entries0 << endl; // Prints "5" for (int i=0; i<vec.length(); i++) cout << vec[i] << endl; return 0; } Program output: 5 entries 22 5.3 -102.5 15 5.3 PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrr RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr<T>(size_t capac=RWDEFAULT_CAPACITY); Create an empty ordered vector with capacity ccccaaaappppaaaacccc. Should the number of items exceed this value, the vector will be resized automatically. RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr<T>(const RWTValOrderedVector<T>& c); Constructs a new ordered vector as a copy of cccc. The copy constructor of all elements in the vector will be called. The new vector will have the same capacity and number of members as the old vector. PPPPuuuubbbblllliiiicccc OOOOppppeeeerrrraaaattttoooorrrrssss RWTValOrderedVector<T>& ooooppppeeeerrrraaaattttoooorrrr====(const RWTValOrderedVector& c); Sets self to a copy of cccc. The copy constructor of all elements in the vector will be called. Self will have the same capacity and number of members as the old vector. T& ooooppppeeeerrrraaaattttoooorrrr(((())))(size_t i); const T& ooooppppeeeerrrraaaattttoooorrrr(((())))(size_t i) const; Returns the iiiith value in the vector. The first variant can be used as an llllvvvvaaaalllluuuueeee, the second cannot. The index iiii must be between zero and the number of items in the collection less one. No bounds checking is performed. PPPPaaaaggggeeee 2222 RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) T& ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i); const T& ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i) const; Returns the iiiith value in the vector. The first variant can be used as an llllvvvvaaaalllluuuueeee, the second cannot. The index iiii must be between zero and the number of items in the collection less one, or an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss void aaaappppppppeeeennnndddd(const T& a); Appends the value aaaa to the end of the vector. The collection will automatically be resized if this causes the number of items in the collection to exceed the capacity. T& aaaatttt(size_t i); const T& aaaatttt(size_t i) const; Return the iiiith value in the vector. The first variant can be used as an llllvvvvaaaalllluuuueeee, the second cannot. The index iiii must be between 0 and the length of the vector less one or an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown. void cccclllleeeeaaaarrrr(); Removes all items from the collection. RWBoolean ccccoooonnnnttttaaaaiiiinnnnssss(const T& a) const; Returns TTTTRRRRUUUUEEEE if the collection contains an item that is equal to aaaa. A linear search is done. Equality is measured by the class-defined equality operator. const T* ddddaaaattttaaaa() const; Returns a pointer to the raw data of the vector. The contents should not be changed. Should be used with care. PPPPaaaaggggeeee 3333 RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) size_t eeeennnnttttrrrriiiieeeessss() const; Returns the number of items currently in the collection. RWBoolean ffffiiiinnnndddd(const T& target, T& ret) const; Performs a linear search and returns TTTTRRRRUUUUEEEE if the vector contains an object that is equal to the object ttttaaaarrrrggggeeeetttt and puts a copy of the matching object into rrrreeeetttt. Returns FFFFAAAALLLLSSSSEEEE otherwise and does not touch rrrreeeetttt. Equality is measured by the class-defined equality operator. T& ffffiiiirrrrsssstttt(); const T& ffffiiiirrrrsssstttt() const; Returns the first item in the collection. An exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will occur if the vector is empty. size_t iiiinnnnddddeeeexxxx(const T& a) const; Performs a linear search, returning the index of the first item that is equal to aaaa. Returns RRRRWWWW____NNNNPPPPOOOOSSSS if there is no such item. Equality is measured by the class-defined equality operator. void iiiinnnnsssseeeerrrrtttt(const T& a); Appends the value aaaa to the end of the vector. The collection will automatically be resized if this causes the number of items in the collection to exceed the capacity. void iiiinnnnsssseeeerrrrttttAAAAtttt(size_t i, const T& a); Inserts the value aaaa into the vector at index iiii. The item previously at position iiii is moved to iiii++++1111, eeeettttcccc. The collection will automatically be resized if this causes the number of items in the collection to exceed the capacity. The index iiii must be between 0 and the number of items in the vector or an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will occur. PPPPaaaaggggeeee 4444 RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RWBoolean iiiissssEEEEmmmmppppttttyyyy() const; Returns TTTTRRRRUUUUEEEE if there are no items in the collection, FFFFAAAALLLLSSSSEEEE otherwise. T& llllaaaasssstttt(); const T& llllaaaasssstttt() const; Returns the last item in the collection. If there are no items in the collection then an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will occur. size_t lllleeeennnnggggtttthhhh() const; Returns the number of items currently in the collection. size_t ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const T& a) const; Performs a linear search, returning the number of items that are equal to aaaa. Equality is measured by the class-defined equality operator. void pppprrrreeeeppppeeeennnndddd(const T& a); Prepends the value aaaa to the beginning of the vector. The collection will automatically be resized if this causes the number of items in the collection to exceed the capacity. RWBoolean rrrreeeemmmmoooovvvveeee(const T& a); Performs a linear search, removing the first object which is equal to the object aaaa and returns TTTTRRRRUUUUEEEE. Returns FFFFAAAALLLLSSSSEEEE if there is no such object. Equality is measured by the class-defined equality operator. size_t rrrreeeemmmmoooovvvveeeeAAAAllllllll(const T& a); Removes all items which are equal to aaaa, returning the number removed. Equality is measured by the class-defined equality operator. PPPPaaaaggggeeee 5555 RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) T rrrreeeemmmmoooovvvveeeeAAAAtttt(size_t i); Removes and returns the object at index iiii. An exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown if iiii is not a valid index. Valid indices are from zero to the number of items in the list less one. T rrrreeeemmmmoooovvvveeeeFFFFiiiirrrrsssstttt(); Removes and returns the first object in the collection. An exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown if the list is empty. T rrrreeeemmmmoooovvvveeeeLLLLaaaasssstttt(); Removes and returns the last object in the collection. An exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown if the list is empty. void rrrreeeessssiiiizzzzeeee(size_t N); Changes the capacity of the collection to NNNN. Note that the number of objects in the collection does not change, just the capacity. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss RWvostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTValOrderedVector<T>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTValOrderedVector<T>& coll); Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to it if it has already been saved. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTValOrderedVector<T>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTValOrderedVector<T>& coll); Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTValOrderedVector<T>*& p); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTValOrderedVector<T>*& p); PPPPaaaaggggeeee 6666 RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a new collection off the heap and sets pppp to point to it, or sets pppp to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it. PPPPaaaaggggeeee 7777